<?php
	require_once (__DIR__.'/LogDao.php');
	
	define("MAIL_TBL", "rate_email_credentials");

	function getMailObject(){
		
		$statement = "SELECT mc.SMTPAuth as SMTPAuth, "
				. "mc.SMTPSecure as SMTPSecure, "
				. "mc.Host as Host, "
				. "mc.Port as Port, "
				. "mc.Username as Username, "
				. "mc.Password as Password, "
				. "mc.FromAdress as FromAdress, "
				. "mc.FromName as FromName "
			. "FROM " . MAIL_TBL . " mc ";
		
		$query = mysql_query($statement);
		
		if(!$query){
			writeError("getMailObject: Cannot query the database: " . mysql_error());
		}
		
		$row = mysql_fetch_array($query);
				
		$mail = new rex_mailer(); 
		$mail->IsSMTP();			// telling the class to use SMTP
		$mail->SMTPAuth   = true;	// enable SMTP authentication
		$mail->SMTPSecure = $row["SMTPSecure"];	// sets the prefix to the servier
		$mail->Host       = $row["Host"];	// sets GMAIL as the SMTP server
		$mail->Port       = $row["Port"];	// set the SMTP port for the GMAIL server
		$mail->Username   = $row["Username"];	// GMAIL username
		$mail->Password   = $row["Password"];	// GMAIL password
		$mail->From = $row["FromAdress"];
		$mail->FromName = $row["FromName"];
		
		return $mail;
	}

	function getDefaultRecipient(){
	
		$statement = "SELECT mc.DefaultRecipient as DefaultRecipient "
			. "FROM " . MAIL_TBL . " mc ";
	
		$query = mysql_query($statement);
		
		if(!$query){
			writeError("getDefaultRecipient: Cannot query the database: " . mysql_error());
		}
		
		$row = mysql_fetch_array($query);		
		
		return $row["DefaultRecipient"];
	}
?>